LanguageModel

interface LanguageModel

Provider-neutral model surface. Per invariant I-4 / I-9, application code never depends on a specific provider — it depends on this interface, and provider-specific differences live in middleware (see LanguageModelMiddleware).

Two operations: generate for one-shot completions, stream for incremental events. Both accept the same LanguageModelCallParams.

Provider implementations live in their own modules:

  • aisdk-provider-litert (Android, on-device)

  • aisdk-provider-mlx (iOS, on-device)

  • aisdk-provider-anthropic / aisdk-provider-openai (cloud, future)

This module ships only ai.torad.aisdk.providers.MockLanguageModel for tests — real providers are out of scope here.

Inheritors

Properties

Link copied to clipboard
abstract val modelId: String

Stable identifier for telemetry / routing ("litertlm/gemma-3-1b", "openai/gpt-5").

Link copied to clipboard
open val provider: String

Provider tag for the model — "openai", "anthropic", "litert-lm", etc. Mirrors v6's LanguageModelV3.provider (per historical parity gap #40). Lets routing layers (a fallback chain, a tier picker) make provider-aware decisions without parsing modelId.

Link copied to clipboard

Map of URL regex → media-tag list describing which URL shapes the provider accepts inline (so the agent doesn't have to download + base64-encode them itself). Mirrors v6's LanguageModelV3.supportedUrls. Empty default — most on-device providers don't accept URLs and fall back to base64.

Functions

Link copied to clipboard

One-shot completion.

Link copied to clipboard
abstract fun stream(params: LanguageModelCallParams): Flow<StreamEvent>

Streaming completion. Cold until collected, then drives one upstream call per collection.

Link copied to clipboard

Streaming completion plus metadata available before stream collection. Implementations must keep the returned stream cold, and must not flowOn/emit from a foreign context — the collection context is the caller's choice. Providers can override this to expose request bodies and response headers while preserving the v6 doStream result shape.